﻿using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace WebApi.Controllers
{
   
    [ApiController]
    public class ErrorController : ControllerBase
    { 
        [Route("/error")]
        [ApiExplorerSettings(IgnoreApi =true)]
        public IActionResult HandError() =>
           Problem("This is a test exception", statusCode: 200, title: "Test Exception");


        [Route("/error-development")]
        [ApiExplorerSettings(IgnoreApi = true)]
        public IActionResult HandErrorDevelopment([FromServices] IHostEnvironment env)
        {
            if (!env.IsDevelopment())
            {
                return NotFound();
            }
            var error = HttpContext.Features.Get<IExceptionHandlerFeature>();
            return Problem(
                detail: error?.Error.StackTrace,
                statusCode: 200,
                title: "Test Exception",
                instance: error?.Path);
        }
    }
}
